package com.hfjyz.exam.object;

public class PageCondition {

	protected int rowCount;
	protected int rowsPerPage = 30;
	protected int page;

	/**
	 * @return the totalCount
	 */
	public int getRowCount() {
		return rowCount;
	}

	/**
	 * @param totalCount
	 *            the totalCount to set
	 */
	public void setRowCount(int totalCount) {
		this.rowCount = totalCount;
	}

	/**
	 * @return the page
	 */
	public int getPage() {
		return page;
	}

	/**
	 * @param page
	 *            the page to set
	 */
	public void setPage(int page) {
		this.page = page;
		if (this.page < 0) {
			this.page = 0;
		}
		if (this.page > getPageCount() - 1) {
			this.page = getPageCount() - 1;
		}
	}

	/**
	 * @return the pageCount
	 */
	public int getPageCount() {
		if (getRowCount() <= 0) {
			return 0;
		}
		return getRowCount() / getRowsPerPage()
				+ (getRowCount() % getRowsPerPage() == 0 ? 0 : 1);
	}

	/**
	 * @return the rowsPerPage
	 */
	public int getRowsPerPage() {
		return rowsPerPage;
	}

	/**
	 * @param rowsPerPage
	 *            the rowsPerPage to set
	 */
	public void setRowsPerPage(int rowsPerPage) {
		this.rowsPerPage = rowsPerPage;
	}

	public int getRowStart() {
		if (rowCount <= 0) {
			return 0;
		}
		return (getPage()) * getRowsPerPage();
	}

	public void next() {
		page++;
		if (page > getPageCount() - 1) {
			page = getPageCount() - 1;
		}
	}

	public void prev() {
		page--;
		if (page < 0) {
			page = 0;
		}
	}

}